package org.geeks.gscaffeine.func;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.CacheWriter;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.RemovalCause;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

@Slf4j
public class CaffeineWriterT {

  @Test
  public void writeAndDelete() throws Exception {
    Cache<String, String> cache =
        Caffeine.newBuilder()
            .writer(
                new CacheWriter<String, String>() {
                  @Override
                  public void write(String key, String value) {
                    log.info("Write key : {}, value : {}", key, value);
                  }

                  @Override
                  public void delete(String key, String value, RemovalCause cause) {
                    log.info("Delete key : {}, value : {}", key, value);
                  }
                })
            .build();

    cache.put("Geek-S", "Hello, world");

    cache.invalidate("Geek-S");
  }
}
